<template lang="html">

  <div class="cartcontrol">
    <transition name="fadeRotate">
      <div class="cart-decrease" v-show="food.num>0" @click.stop.prevent="increaseCart()">
          <i class="icon-remove_circle_outline inner" style="color:#f98b5f;"></i>
      </div>
    </transition>
    <div class="cart-count" v-show="food.num>0">
      {{food.num}}
    </div>
    <div class="cart-add" @click.stop.prevent="addCart($event)">
      <i class="icon-add_circle" style="color:RGB(255,97,3);"></i>
    </div>
  </div>

</template>

<script>
	export default{
		data(){
			return {
				chosetype:0,
				tostorefood:{},
			}
		},
		props:{
			food:{
				type:Object
			},
			index:{
				type:Number
			}
		},
		computed:{
			addtype:function(){
				if(this.food.ogndishespriceList.length==1&&(this.food.ogndishestasteList.length==0||!this.food.ogndishestasteList)&&(this.food.ogndishesavoList.length==0||!this.food.ogndishesavoList)&&(this.food.ogndishespackList.length==0||!this.food.ogndishespackList)){
					this.chosetype=0 //0是没有规格没有口味没有忌口没有套餐
				}
				else if((this.food.ogndishespackList.length>0&&this.food.ogndishespackList)){
					this.chosetype=1  //1是有套餐
				}
				else{
					this.chosetype=2//2是有多规格或者有口味选择或者有忌口选择
				}
			},
			shopfood:function(){
				if(this.chosetype==2){
				var postfood={
					taste:{
						avo:[]
					}
				}
				this.food.ogndishespriceList.forEach(function(guige){
					if(guige.chosed){
						postfood.specif=guige.unit.unitname
						postfood.price=guige.dishesprice
					}
				})
				this.food.ogndishestasteList.forEach(function(taste){
					if(taste.chosed){
						postfood.taste.tast=taste.taste.tastename
					}
				})
				this.food.ogndishesavoList.forEach(function(avo){
					if(avo.chosed){
						postfood.taste.avo.push(avo.avo.avoname)
					}
				})
				postfood.name=this.food.dishes.dishesname
				this.tostorefood=postfood;
			}
			}
		},
		methods:{
			radom:function(min, max){
				return 	parseFloat(Math.random() * (max - min) + min).toFixed(2)
				},
			addCart:function(event){
					this.food.num++;
					this.$store.commit("getjustprice",this.food.price)
					this.$emit('chan',this.index);
				this.$emit("cartadd",event.target)
						if(this.$store.state.doubleused&&!this.$store.state.doubleuseded&&!this.$store.state.doublenumused){
							var money=this.radom(this.food.firstGearMin,this.food.firstGearMax)
							var money1=this.radom(this.food.firstGearMin,this.food.firstGearMax)
							if((money*2*this.food.price).toFixed(2)==0){
								return
							}
							this.food.hongbao.push((money*this.food.price).toFixed(2))
							this.food.hongbao.push((money1*this.food.price).toFixed(2))
							this.food.doublehongbao=true
							this.$store.commit("addhongbao",[(money*this.food.price).toFixed(2),(money1*this.food.price).toFixed(2)])
							this.$store.commit("getdoubleuseded")
						}
						else if(this.$store.state.doublenumused&&!this.$store.state.doublenumuseded&&(this.$store.state.totalcount+1)>=sessionStorage.doubletype){
							var money=this.radom(this.food.firstGearMin,this.food.firstGearMax)
								var money1=this.radom(this.food.firstGearMin,this.food.firstGearMax)
								if((money*2*this.food.price).toFixed(2)==0){
								return
							}
							this.food.hongbao.push((money*this.food.price).toFixed(2))
							this.food.hongbao.push((money1*this.food.price).toFixed(2))
							this.food.doublehongbao=true
							this.$store.commit("addhongbao",[(money*this.food.price).toFixed(2),(money1*this.food.price).toFixed(2)])
							this.$store.commit("getdoublenumuseded")
						}
						else if(this.$store.state.hongbaonum==(sessionStorage.bignum-1)&&sessionStorage.tape>0&&!this.$store.state.jingxiused){
							
							var money=this.radom(this.food.secondGearMin,this.food.secondGearMax)
							if((money*this.food.price).toFixed(2)==0){
								return
							}
							this.$store.commit("getotherhongbao","（惊喜）")
							this.$store.commit("getjingxiused",money*this.food.price)
							this.food.jingxiused=money*this.food.price
							this.$store.commit("addhongbao",(money*this.food.price).toFixed(2))
						}
						else{
							var money=this.radom(this.food.firstGearMin,this.food.firstGearMax)
							if((money*this.food.price).toFixed(2)==0){
								return
							}
							this.food.hongbao.push((money*this.food.price).toFixed(2))
							this.$store.commit("addhongbao",(money*this.food.price).toFixed(2))
						}
			},
			increaseCart:function(){
//				if(!event._constructed){//如果不存在这个属性,则不执行下面的函数
//      return;
//  }
				if(this.food.num!=0){

					this.food.num--;
					if(this.food.jingxiused){
						this.$store.commit("overjingxiused")
						this.food.jingxiused=0
					}
					else{
						this.food.hongbao.pop()
					}
					if(this.food.doublehongbao){
						
						this.food.doublehongbao=false
						this.$store.commit("overdoubleuseded")
						this.$store.commit("overdoublenumuseded")
					}
					if(this.food.doublehongbao){
						
						this.food.doublehongbao=false
						this.$store.commit("overdoubleuseded")
						this.$store.commit("overdoublenumuseded")
					}
					console.log(this.food)

				}
			}
		}
	}
</script>

<style lang="stylus">

.cartcontrol
  vertical-align middle
  .cart-decrease
    vertical-align middle  
    display inline-block
    transition: all .4s linear
    line-height 24px
    font-size 24px
    .inner
      color rgb(0,160,220)
      transition all 0.4s linear
    &.fadeRotate-enter-active, &.fadeRotate-leave-active
      transform translate3d(0,0,0)
      .inner
        display inline-block
        transform rotate(0)
    &.fadeRotate-enter, &.fadeRotate-leave-to
      opacity: 0
      transform translate3d(24px,0,0)
      .inner
        transform rotate(180deg)
  .cart-count
    display inline-block
    vertical-align middle
    font-size 15px
    font-weight 700
    color black
    line-height 24px
    text-align center
  .cart-add
    display inline-block
    vertical-align middle
    font-size 24px
    color rgb(0,160,220)
    line-height 24px
</style>